package com.ley.yikang.service.serviceimpl;

import com.ley.yikang.entity.Elder;
import com.ley.yikang.mapper.ElderMapper;
import com.ley.yikang.service.ElderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ElderServiceImpl implements ElderService {
    private final ElderMapper elderMapper;

    @Autowired
    public ElderServiceImpl(ElderMapper elderMapper) {
        this.elderMapper = elderMapper;
    }

    @Override
    public void addElder(Elder elder) {
        elderMapper.addElder(elder);
    }

    @Override
    public List<Elder> findAll(String elderName, String phone, Integer communityId) {
        Map<String, Object> params = new HashMap<>();
        if (elderName != null && !elderName.isEmpty()) {
            params.put("elderName", elderName);
        }
        if (phone != null && !phone.isEmpty()) {
            params.put("phone", phone);
        }
        if (communityId != null) {
            params.put("communityId", communityId);
        }
        return elderMapper.findAll(params);
    }

    @Override
    public Elder findElder(String phone) {
        return elderMapper.findElder(phone);
    }

    @Override
    public Elder findElderById(int id) {
        return elderMapper.findElderById(id);
    }

    @Override
    public void delElder(int id) {
        elderMapper.delElder(id);
    }

    @Override
    public void updateElder(Elder elder) {
        elderMapper.updateElder(elder);
    }

    @Override
    public List<Elder> getCommunityElder(int communityId) {
        return elderMapper.getCommunityElder(communityId);
    }
}
